package com.hanliy.interceptor;

import com.alipay.api.AlipayApiException;
import com.hanliy.controller.OrderController;
import com.ijpay.alipay.AliPayApiConfigKit;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author hanyulin
 * @apiNote
 * @date 2022/2/9 9:34
 */
public class AliPayInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler) throws AlipayApiException {
        if (HandlerMethod.class.equals(handler.getClass())) {
            HandlerMethod method = (HandlerMethod) handler;
            Object methodBean = method.getBean();
            AliPayApiConfigKit.setThreadLocalAliPayApiConfig(((OrderController) methodBean).getApiConfig());
            return true;
        }
        return false;
    }
}
